//--------------------------------------------------------------------------
// 
//  Copyright (c) Chili Software.  All rights reserved. 
// 
//  File: RelatedPropertiesPairCollection.cs
//
//  Description: Holds a list related properties pairs.
// 
//--------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Chili.Opf3.Mapping
{
	/// <summary>
	/// This class contains a list of <see cref="RelatedPropertiesPair">RelatedPropertiesPair</see> classes.
	/// </summary>
	internal sealed class RelatedPropertiesPairCollection : IRelatedPropertiesPairCollection
	{
		private List<IRelatedPropertiesPair> _propertiesParis = new List<IRelatedPropertiesPair>();

		/// <summary>
		/// Adds the <see cref="RelatedPropertiesPair">RelatedPropertiesPair</see> object to the list.
		/// </summary>
		/// <param name="pair">The object that is added.</param>
		internal void Add(RelatedPropertiesPair pair)
		{
			if (pair == null)
				throw new ArgumentNullException("pair");

			_propertiesParis.Add(pair);
		}

		/// <summary>
		/// Determines whether an element is in the collection.
		/// </summary>
		/// <param name="item">The object to locate in the collection.</param>
		/// <returns>True if item is found in the collection; otherwise, false.</returns>
		public bool Contains(IRelatedPropertiesPair item)
		{
			return _propertiesParis.Contains(item);
		}

		/// <summary>
		/// Copies the entire collection to a compatible one-dimensional array, starting at the specified index of the target array.
		/// </summary>
		/// <param name="array">The one-dimensional System.Array that is the destination of the elements copied from collection. The System.Array must have zero-based indexing.</param>
		/// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
		public void CopyTo(IRelatedPropertiesPair[] array, int arrayIndex)
		{
			_propertiesParis.CopyTo(array, arrayIndex);
		}

		/// <summary>
		/// Gets the number of elements actually contained in the collection.
		/// </summary>
		public int Count
		{
			get { return _propertiesParis.Count; }
		}

		/// <summary>
		/// Returns whether the collection is read-only.
		/// </summary>
		public bool IsReadOnly
		{
			get { return true; }
		}

		/// <summary>
		/// Returns the item at the given index.
		/// </summary>
		/// <param name="index">The index of the item that is returned.</param>
		/// <returns>The item at the given index.</returns>
		public IRelatedPropertiesPair this[int index]
		{
			get { return _propertiesParis[index]; }
		}

		#region IEnumerable<IMemberInfo> Members

		/// <summary>
		/// Returns an enumerator that iterates through the collection.
		/// </summary>
		/// <returns> A enumerator that can be used to iterate through the collection.</returns>
		public IEnumerator<IRelatedPropertiesPair> GetEnumerator()
		{
			return _propertiesParis.GetEnumerator();
		}

		#endregion

		#region IEnumerable Members

		/// <summary>
		/// Returns an enumerator that iterates through a collection.
		/// </summary>
		/// <returns>An enumerator object that can be used to iterate through the collection.</returns>
		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return ((IEnumerable)_propertiesParis).GetEnumerator();
		}

		#endregion
	}
}
